package com.tc.travel.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.tc.travel.util.exception.ComRuntimeException;

public class DateUtil {
	public static String formatToDestStyle(String dateStr) {
		return format(parse(dateStr), "yyyy/MM/dd");
	}

	public static String format(Date date, String format) {
		if (date == null) {
			return "";
		}

		return new SimpleDateFormat(format).format(date);
	}

	public static Date parse(String strDate) {
		if (strDate == null) {
			throw new ComRuntimeException("日期不能为空.");
		}

		try {
			if (strDate.matches("\\d{4}-\\d{2}-\\d{2}")) {
				return new SimpleDateFormat("yyyy-MM-dd").parse(strDate);
			}
		} catch (ParseException e) {
		}

		throw new ComRuntimeException("日期格式不正确:" + strDate);
	}

}
